import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Bora SAYINER
 * @since Dec 14, 2014 12:43:32 PM
 * @version 1.0
 */
public class Driver {

	public static void main(String[] args) {
		JFrame frmMain = new JFrame();
		frmMain.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosed(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowActivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
		frmMain.setTitle("Border Layout");
		frmMain.setSize(300, 150);
		frmMain.setLocationRelativeTo(null);
		frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		{
			JPanel pnlCenter = new JPanel();
			{
				{
					JButton button = new JButton("Click Me");
					// ButonaTiklandi butonaTiklandi = new ButonaTiklandi();
					// button.addActionListener(butonaTiklandi);
					button.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							System.out.println("Anonymous butona tıklandı");
						}
					});
					pnlCenter.add(button);
				}
				{
					JButton button = new JButton("Mesaj göster");
					button.addActionListener(new ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							JOptionPane.showMessageDialog(null,
									"Bu bir uyarı mesajıdır", "Başlık",
									JOptionPane.WARNING_MESSAGE);
						}
					});
					pnlCenter.add(button);
				}
				{
					JButton button = new JButton("Dosya seç");
					button.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							JButton button = (JButton) e.getSource();
							System.out.println(new Date(e.getWhen()));
							button.setText("Tıklandı");
							// JFileChooser fileChooser = new JFileChooser();
							// fileChooser.showOpenDialog(null);
						}
					});
					pnlCenter.add(button);
				}
				ActionListener buttonListener = new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						if (e.getActionCommand().equals("ilk buton")) {
							System.out.println("birinci butona tıklandı");
						} else if (e.getActionCommand().equals("ikinci buton")) {
							System.out.println("ikinci butona tıklandı");
						}
					}
				};
				{
					JButton button = new JButton();
					button.setText("1. button");
					button.setActionCommand("ilk buton");
					button.addActionListener(buttonListener);
					pnlCenter.add(button);
				}
				{
					JButton button = new JButton();
					button.setText("2. button");
					button.setActionCommand("ikinci buton");
					button.addActionListener(buttonListener);
					pnlCenter.add(button);
				}
				{
					JTextField textField = new JTextField(20);
					textField.addKeyListener(new KeyListener() {

						@Override
						public void keyTyped(KeyEvent e) {
							// TODO Auto-generated method stub

						}

						@Override
						public void keyReleased(KeyEvent e) {
							// TODO Auto-generated method stub

						}

						@Override
						public void keyPressed(KeyEvent e) {
							System.out.println(e.getKeyCode());
							if (e.getKeyCode() == KeyEvent.VK_ENTER) {
								textField.setBackground(Color.YELLOW);
							}
							// String text = textField.getText();
							// if (text.trim().length()>=10) {
							// textField.setBackground(Color.RED);
							// }else {
							// textField.setBackground(Color.WHITE);
							// }

						}

					});
					pnlCenter.add(textField);
				}

				{
					JButton button = new JButton("Çıkış");
					button.addActionListener(new ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							int result = JOptionPane.showConfirmDialog(null,
									"Kapatmak istediğinden emin misiniz?",
									"Soru", JOptionPane.YES_NO_OPTION);
							if (result == JOptionPane.YES_OPTION) {
								System.exit(0);
							}
						}
					});
					pnlCenter.add(button);
				}

				{
					JComboBox<String> iller = new JComboBox<String>();
					iller.addItem("İstanbul");
					iller.addItem("Ankara");
					iller.addItem("Trabzon");
					iller.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							System.out.println(iller.getSelectedItem());
						}
					});
					pnlCenter.add(iller);
				}
				{
					JButton button = new JButton("Mouse test");
					Color eskiBgColor = button.getBackground();
					Color eskiFgColor = button.getForeground();
					button.addMouseListener(new MouseListener() {

						@Override
						public void mouseReleased(MouseEvent e) {
							// TODO Auto-generated method stub

						}

						@Override
						public void mousePressed(MouseEvent e) {
							// TODO Auto-generated method stub

						}

						@Override
						public void mouseExited(MouseEvent e) {
							button.setBackground(eskiBgColor);
							button.setForeground(eskiFgColor);
						}

						@Override
						public void mouseEntered(MouseEvent e) {
							button.setBackground(Color.BLUE);
							button.setForeground(Color.YELLOW);
						}

						@Override
						public void mouseClicked(MouseEvent e) {
							// TODO Auto-generated method stub

						}
					});
					pnlCenter.add(button);
				}

			}
			frmMain.add(pnlCenter, BorderLayout.CENTER);
		}
		frmMain.setVisible(true);
	}
}
